#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

int m, n, k, l, d;

struct node{
	int seat;
	int num;
};

node row[N], col[N];

bool cmp1(node x1, node x2)
{
	return x1.num > x2.num;
}

bool cmp2(node x1, node x2)
{
	return x1.seat < x2.seat;
}

int main()
{
	cin >> m >> n >> k >> l >> d;
	
	for(int i = 1; i <= m; i++) cin >> row[i].seat;
	for(int i = 1; i <= n; i++) cin >> col[i].seat;
	
	for(int i = 1; i <= d; i++)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if(x1 == x2) col[min(y1, y2)].num++;
		else row[min(x1, x2)].num++;
	}
	
	sort(row + 1, row + m + 1, cmp1);
	sort(col + 1, col + n + 1, cmp1); 
	
	sort(row + 1, row + k + 1, cmp2);
	sort(col + 1, col + l + 1, cmp2;)
	
	for(int i = 1, i <= k; i++) cout << row[i].seat << " ";
	cout << endl;
	for(int i = 1; i <= l; i++) cout << col[i].seat << " ";
	cout << endl;
	 
	return 0;
}
 
